<?php


use Phinx\Seed\AbstractSeed;
use Faker\Factory as FakerFactory;

class PageSeeder extends AbstractSeed
{
    /**
     * Run Method.
     *
     * Write your database seeder using this method.
     *
     * More information on writing seeders is available here:
     * https://book.cakephp.org/phinx/0/en/seeding.html
     */
    public function run()
    {
        $faker = FakerFactory::create('zh_CN');

        $titles = $this->getTitles();

        $rows = [];
        foreach ($titles as $title) {
            $rows[] = [
                'title' => $title,
                'content' => $faker->text(200),
                'published' => 1,
                'create_time' => $faker->unixTime,
                'update_time' => $faker->unixTime,
            ];
        }

        $this->table('kg_page')->insert($rows)->saveData();
    }

    protected function getTitles(): array
    {
        return [
            '关于我们',
            '人才招聘',
            '联系我们',
            '友情链接',
            '使用协议',
        ];
    }
}
